function [y_predict,MSE] = EnsembleR(train_data,train_labels,test_data,test_labels,Default)

predictions=[];
labels=[];
errors=[];
% scores=[];

if Default
    tic
    load("EnsembleR_BestModel.mat");
    toc
else

    BestModel = fitrensemble(train_data, train_labels,...
        'Learners','tree',...
        'Method','LSBoost', ...
        'HyperparameterOptimizationOptions',struct('Optimizer','bayesopt', ...
        'KFold',5,...
        'MaxObjectiveEvaluations',100,...
        'Repartition',true,...
        'NumGridDivisions',100), ...
        'OptimizeHyperparameters','all')

    save("EnsembleR_BestModel",'BestModel');

end

y_predict=predict(BestModel,test_data);
MSE=mse(y_predict,test_labels);
error =zeros(length(test_data),1);
index = abs(y_predict-test_labels)>0.2;
error(index) = 1;
resultTable=table(test_data,test_labels,y_predict,error);
filename = 'EnsembleR.xlsx';
writetable(resultTable,filename,'Sheet',1,'Range','A1')
end